package com.yztc.orangeentertainment.ui.main.channalarticle;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.SpannableString;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.facebook.drawee.view.SimpleDraweeView;
import com.litesuits.orm.db.assit.WhereBuilder;
import com.opendanmaku.DanmakuItem;
import com.opendanmaku.DanmakuView;
import com.opendanmaku.IDanmakuItem;
import com.yztc.orangeentertainment.App;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.adapter.ChannalArticleCommentAdapter;
import com.yztc.orangeentertainment.adapter.ChannalArticleContentAdapter;
import com.yztc.orangeentertainment.adapter.ChannalArticleJinBaoAdapter;
import com.yztc.orangeentertainment.adapter.ChannalArticleTuiJianAdapter;
import com.yztc.orangeentertainment.adapter.ChannalArticleVoteAdapter;
import com.yztc.orangeentertainment.base.BaseActivity;
import com.yztc.orangeentertainment.base.OnItemClickListener;
import com.yztc.orangeentertainment.bean.articlecommentall.ArticleCommentAllListBean;
import com.yztc.orangeentertainment.bean.channalarticle.ChannalArticleAttitudeBean;
import com.yztc.orangeentertainment.bean.channalarticle.ChannalArticleFooterBean;
import com.yztc.orangeentertainment.bean.channalarticle.ChannalArticleIMGBean;
import com.yztc.orangeentertainment.bean.channalarticle.ChannalArticleInfoBean;
import com.yztc.orangeentertainment.bean.channalarticle.ChannalArticleRecommendBean;
import com.yztc.orangeentertainment.bean.channalarticle.ChannalArticleTagsBean;
import com.yztc.orangeentertainment.bean.channalarticle.ChannalArticleVoteBean;
import com.yztc.orangeentertainment.bean.channalarticlecomment.ArticleBean;
import com.yztc.orangeentertainment.bean.channalarticlecomment.ArticleCommentAttitudeBean;
import com.yztc.orangeentertainment.bean.channalarticlecomment.ArticleCommentBean;
import com.yztc.orangeentertainment.bean.channalarticlecomment.ArticleCommentFirstListBean;
import com.yztc.orangeentertainment.bean.shoucang.ShouCang;
import com.yztc.orangeentertainment.ui.main.ArticleShouCang.ArticleShouCangActivity;
import com.yztc.orangeentertainment.ui.main.articlecommentall.ArticleCommentAllActivity;
import com.yztc.orangeentertainment.ui.main.articlecommentall.ArticleCommentAllContract;
import com.yztc.orangeentertainment.ui.main.articlecommentall.ArticleCommentAllPresenter;
import com.yztc.orangeentertainment.ui.main.subscribefragment.contentitem.CategoryActivity;
import com.yztc.orangeentertainment.ui.main.subscribefragment.staritem.StarItemActivity;
import com.yztc.orangeentertainment.utils.DividerItemDecoration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.tencent.qzone.QZone;
import cn.sharesdk.wechat.favorite.WechatFavorite;
import cn.sharesdk.wechat.friends.Wechat;

/**
 * Created by My on 2016/10/10.
 */
public class ChannalArticleActivity extends BaseActivity implements ChannalArticleContract.View,
        View.OnClickListener,ArticleCommentAllContract.View {
    @InjectView(R.id.iv_channalarticlebg)
    ImageView ivChannalarticlebg;
    @InjectView(R.id.tv_channalarticleiconname)
    TextView tvChannalarticleiconname;
    @InjectView(R.id.tv_channalarticletitle)
    TextView tvChannalarticletitle;
    @InjectView(R.id.tv_channalarticleauthor)
    TextView tvChannalarticleauthor;
    @InjectView(R.id.tv_channalarticletime)
    TextView tvChannalarticletime;
    @InjectView(R.id.ib_channalarticleback)
    SimpleDraweeView ibChannalarticleback;
    @InjectView(R.id.et_channalarticledanmu)
    EditText etChannalarticledanmu;
    @InjectView(R.id.iv_channalarticlecomment)
    ImageView ivChannalarticlecomment;
    @InjectView(R.id.tv_channalarticlecommentnum)
    TextView tvChannalarticlecommentnum;
    @InjectView(R.id.rl_channalarticle)
    RelativeLayout rlChannalarticle;
    @InjectView(R.id.iv_channalarticlebullt)
    ImageView ivChannalarticlebullt;
    @InjectView(R.id.iv_channalarticleshare)
    ImageView ivChannalarticleshare;
    @InjectView(R.id.iv_channalarticleshoucang)
    ImageView ivChannalarticleshoucang;
    @InjectView(R.id.danmakuView)
    DanmakuView mDanmakuView;
    @InjectView(R.id.rl_all)
    RelativeLayout rlAll;
    private NestedScrollView ns_channalarticle;
    private ChannalArticlePresenter presenter;
    private TextView tv_votenum, tv_articleCommmentmore;
    private int voteNum,page=1;
    private String id, readnum, iconimage;
    private ImageView iv_weixinquan, iv_weixin, iv_qzone, iv_qq, iv_weibo;
    private ChannalArticleInfoBean infoBeanList;
    private RecyclerView rv_channalarticlecomment, rv_articleAttitude, rv_articlejinbao,
            rv_articleTuiJian, rv_articleContent;
    private boolean flag;
    private List<IDanmakuItem> list = new ArrayList<>();
    private Button button;
    private boolean falg;
    private PopupWindow popupWindow;
    private ArticleCommentAllPresenter commentAllPresenter;
    private DanmakuItem mIDanmakuItem;
    private List<ChannalArticleVoteBean> voteBeanList = new ArrayList<>();
    private List<ChannalArticleAttitudeBean> attitudeBeanList = new ArrayList<>();

    @Override
    public int getLayoutId() {
        return R.layout.channal_article;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ShareSDK.initSDK(this);
        ButterKnife.inject(this);
        Intent intent = getIntent();
        id = intent.getStringExtra("id");
        readnum = intent.getStringExtra("readnum");
        iconimage = intent.getStringExtra("iconimage");
        initView();
        initshareView();
        initContentView();
        initJinBaoView();
        initAttitudeView();
        initTuiJIanView();
        initCommentView();
        initCommentPresent();
        presenter = new ChannalArticlePresenter(this);
        presenter.getChannalArticleFromNet(this, id);
        presenter.getChannalArticleCommentFromNet(this, id);
       /* ns_channalarticle.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {

            }
        });*/
    }

    private void initCommentPresent() {
        commentAllPresenter = new ArticleCommentAllPresenter(this);
        commentAllPresenter.getArticleCommentAllFromNet(this, Integer.parseInt(id), page);
    }

    /**
     * 实例化分享页面的控件
     */
    private void initshareView() {
        View shareView = findViewById(R.id.in_channalarticle);
        iv_qq = (ImageView) shareView.findViewById(R.id.share_qq);
        iv_qzone = (ImageView) shareView.findViewById(R.id.share_Qzone);
        iv_weibo = (ImageView) shareView.findViewById(R.id.share_weibo);
        iv_weixinquan = (ImageView) shareView.findViewById(R.id.share_weixinquan);
        iv_weixin = (ImageView) shareView.findViewById(R.id.share_weixin);
        //微信分享功能的实现
        iv_weixin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //1.获取当前分享的平台的实例
                Platform platform = ShareSDK.getPlatform(Wechat.NAME);
                //2.添加相应的监听事件
                platform.setPlatformActionListener(new PlatformActionListener() {
                    //表示分享执行回调的函数
                    @Override
                    public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
                        if (action == Platform.ACTION_AUTHORIZING) {
                            Log.i("tag", "授权成功");
                            //构建分享的对象
                            Wechat.ShareParams params = new Wechat.ShareParams();
                            params.setText(infoBeanList.getTitle());
                            params.setImageUrl(infoBeanList.getImg());
                            //启动分享
                            platform.share(params);
                        } else if (action == Platform.ACTION_SHARE) {//分享成功
                            Log.i("tag", "分享成功");
                        }
                    }

                    //表示分享出错时回调
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("tag", "分享出错");
                        throwable.printStackTrace();
                    }

                    //取消分享时回调的
                    @Override
                    public void onCancel(Platform platform, int i) {
                        Log.i("tag", "取消分享");
                    }
                });
                //3.授权
                platform.authorize();
            }
        });
        //QQ控件分享功能的实现
        iv_qzone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //1.获取当前分享的平台的实例
                Platform platform = ShareSDK.getPlatform(QZone.NAME);
                //2.添加相应的监听事件
                platform.setPlatformActionListener(new PlatformActionListener() {
                    //表示分享执行回调的函数
                    @Override
                    public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
                        if (action == Platform.ACTION_AUTHORIZING) {
                            Log.i("tag", "授权成功");
                            //构建分享的对象
                            QZone.ShareParams params = new QZone.ShareParams();
                            params.setText(infoBeanList.getTitle());
                            params.setImageUrl(infoBeanList.getImg());
                            //启动分享
                            platform.share(params);
                        } else if (action == Platform.ACTION_SHARE) {//分享成功
                            Log.i("tag", "分享成功");
                        }
                    }

                    //表示分享出错时回调
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("tag", "分享出错");
                        throwable.printStackTrace();
                    }

                    //取消分享时回调的
                    @Override
                    public void onCancel(Platform platform, int i) {
                        Log.i("tag", "取消分享");
                    }
                });
                //3.授权
                platform.authorize();
            }
        });
        //qq分享功能的实现
        iv_qq.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //1.获取当前分享的平台的实例
                Platform platform = ShareSDK.getPlatform(QQ.NAME);
                //2.添加相应的监听事件
                platform.setPlatformActionListener(new PlatformActionListener() {
                    //表示分享执行回调的函数
                    @Override
                    public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
                        if (action == Platform.ACTION_AUTHORIZING) {
                            Log.i("tag", "授权成功");
                            //构建分享的对象
                            QQ.ShareParams params = new QQ.ShareParams();
                            params.setText(infoBeanList.getTitle());
                            params.setImageUrl(infoBeanList.getImg());
                            //启动分享
                            platform.share(params);
                        } else if (action == Platform.ACTION_SHARE) {//分享成功
                            Log.i("tag", "分享成功");
                        }
                    }

                    //表示分享出错时回调
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("tag", "分享出错");
                        throwable.printStackTrace();
                    }

                    //取消分享时回调的
                    @Override
                    public void onCancel(Platform platform, int i) {
                        Log.i("tag", "取消分享");
                    }
                });
                //3.授权
                platform.authorize();
            }
        });
        //微信朋友圈功能的实现
        iv_weixinquan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //1.获取当前分享的平台的实例
                Platform platform = ShareSDK.getPlatform(WechatFavorite.NAME);
                //2.添加相应的监听事件
                platform.setPlatformActionListener(new PlatformActionListener() {
                    //表示分享执行回调的函数
                    @Override
                    public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
                        if (action == Platform.ACTION_AUTHORIZING) {
                            Log.i("tag", "授权成功");
                            //构建分享的对象
                            WechatFavorite.ShareParams params = new WechatFavorite.ShareParams();
                            params.setText(infoBeanList.getTitle());
                            params.setImageUrl(infoBeanList.getImg());
                            //启动分享
                            platform.share(params);
                        } else if (action == Platform.ACTION_SHARE) {//分享成功
                            Log.i("tag", "分享成功");
                        }
                    }

                    //表示分享出错时回调
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("tag", "分享出错");
                        throwable.printStackTrace();
                    }

                    //取消分享时回调的
                    @Override
                    public void onCancel(Platform platform, int i) {
                        Log.i("tag", "取消分享");
                    }
                });
                //3.授权
                platform.authorize();
            }
        });
        //新浪微博功能的实现
        iv_weibo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //1.获取当前分享的平台的实例
                Platform platform = ShareSDK.getPlatform(SinaWeibo.NAME);
                //2.添加相应的监听事件
                platform.setPlatformActionListener(new PlatformActionListener() {
                    //表示分享执行回调的函数
                    @Override
                    public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
                        if (action == Platform.ACTION_AUTHORIZING) {
                            Log.i("tag", "授权成功");
                            //构建分享的对象
                            SinaWeibo.ShareParams params = new SinaWeibo.ShareParams();
                            params.setText(infoBeanList.getTitle());
                            params.setImageUrl(infoBeanList.getImg());
                            //启动分享
                            platform.share(params);
                        } else if (action == Platform.ACTION_SHARE) {//分享成功
                            Log.i("tag", "分享成功");
                        }
                    }

                    //表示分享出错时回调
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("tag", "分享出错");
                        throwable.printStackTrace();
                    }

                    //取消分享时回调的
                    @Override
                    public void onCancel(Platform platform, int i) {
                        Log.i("tag", "取消分享");
                    }
                });
                //3.授权
                platform.authorize();
            }
        });
    }

    //实现控件的功能
    private void initView() {
        ibChannalarticleback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ivChannalarticleshare.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                    return;
                } else {
                    initPopupWindows();
                    popupWindow.showAtLocation(rlAll, Gravity.FILL, 0, 0);
                }
            }
        });
        ShouCang shouCang1 = App.getLiteOrm().queryById(id, ShouCang.class);
        if (shouCang1 == null) {
            flag = false;
            ivChannalarticleshoucang.setImageResource(R.mipmap.btn_detail_collect_normal_new);
        } else {
            flag = true;
            ivChannalarticleshoucang.setImageResource(R.mipmap.btn_detail_collect_selected);
        }
        ivChannalarticleshoucang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (flag == false) {
                    Intent intent = new Intent(ChannalArticleActivity.this, ArticleShouCangActivity
                            .class);
                    ShouCang shouCang = new ShouCang();
                    shouCang.setId(infoBeanList.getId());
                    shouCang.setTitle(infoBeanList.getTitle());
                    shouCang.setBgimage(infoBeanList.getImg());
                    shouCang.setIconimage(iconimage);
                    shouCang.setIconname(infoBeanList.getCat().getName());
                    shouCang.setReadnum(readnum);
                    long l = App.getLiteOrm().insert(shouCang);

                    if (l > 0) {
                        flag = true;
                        Toast.makeText(ChannalArticleActivity.this, "收藏成功", Toast.LENGTH_SHORT).show();
                        ivChannalarticleshoucang.setImageResource(R.mipmap.btn_detail_collect_selected);
                    }
                } else {
                    int num = App.getLiteOrm().delete(new WhereBuilder(ShouCang.class).where
                            ("id" + "=?", new Object[]{infoBeanList.getId() + ""}));

                    if (num > 0) {
                        flag = false;
                        Toast.makeText(ChannalArticleActivity.this, "取消成功", Toast.LENGTH_SHORT).show();
                        ivChannalarticleshoucang.setImageResource(R.mipmap.btn_detail_collect_normal_new);
                    }

                }
            }
        });
    }

    private void initPopupWindows() {
        View customView = LayoutInflater.from(ChannalArticleActivity.this).inflate(R.layout
                .sharesdk, null);
        ViewHolder viewHolder=new ViewHolder(customView);
        popupWindow = new PopupWindow(customView, ViewPager.LayoutParams.MATCH_PARENT, ViewPager
                .LayoutParams.MATCH_PARENT);
        //设置popupwindow进出动画
        popupWindow.setAnimationStyle(R.style.AnimationFade);
        customView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        viewHolder.rlShareCopy.setOnClickListener(this);
        viewHolder.rlShareQq.setOnClickListener(this);
        viewHolder.rlShareQzone.setOnClickListener(this);
        viewHolder.rlShareWeibo.setOnClickListener(this);

    }

    //实例化评论小页面的空间
    private void initCommentView() {
        tv_articleCommmentmore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ChannalArticleActivity.this, ArticleCommentAllActivity
                        .class);
                intent.putExtra("id", id);
                startActivity(intent);
            }
        });

        //ns_channalarticle= (NestedScrollView) findViewById(R.id.ns_channalarticle);
        rlChannalarticle = (RelativeLayout) findViewById(R.id.rl_channalarticle);
        rlChannalarticle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ChannalArticleActivity.this, ArticleCommentAllActivity
                        .class);
                intent.putExtra("id", id);
                startActivity(intent);
            }
        });
        View commentView = findViewById(R.id.in_articlecomment);
        rv_channalarticlecomment = (RecyclerView) commentView.findViewById(R.id
                .rv_channalarticlecomment);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        //垂直摆放
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        //间距
        rv_channalarticlecomment.addItemDecoration(new DividerItemDecoration(5));
        rv_channalarticlecomment.setLayoutManager(linearLayoutManager);


    }

    //实例化投票小页面的控件
    private void initAttitudeView() {
        View attitudeView = findViewById(R.id.in_articlevote);
        rv_articleAttitude = (RecyclerView) attitudeView.findViewById(R.id.rv_channalarticlevote);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        //水平摆放
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        //间距
        rv_articleAttitude.addItemDecoration(new DividerItemDecoration(5));
        rv_articleAttitude.setLayoutManager(linearLayoutManager);
        tv_votenum = (TextView) attitudeView.findViewById(R.id.tv_channalarticlevotenum);

    }

    //实例化内容页面的控件
    private void initContentView() {
        tv_articleCommmentmore = (TextView) findViewById(R.id.tv_channalarticlecommentmore);
        View contentView = findViewById(R.id.in_channalarticle);
        rv_articleContent = (RecyclerView) contentView.findViewById(R.id.rv_channalarticlecontent);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        //垂直摆放
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        //间距
        rv_articleContent.addItemDecoration(new DividerItemDecoration(5));
        rv_articleContent.setLayoutManager(linearLayoutManager);
    }

    //实例化推荐小页面的控件
    private void initTuiJIanView() {
        View tuiJianView = findViewById(R.id.in_aticletuijian);
        rv_articleTuiJian = (RecyclerView) tuiJianView.findViewById(R.id.rv_articletuijian);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        //水平摆放
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        //间距
        rv_articleTuiJian.addItemDecoration(new DividerItemDecoration(5));
        rv_articleTuiJian.setLayoutManager(linearLayoutManager);
    }

    //实例化劲爆小页面的控件
    private void initJinBaoView() {
        View jinBaoView = findViewById(R.id.in_articlejinbao);
        rv_articlejinbao = (RecyclerView) jinBaoView.findViewById(R.id.rv_articlejinbao);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        //水平摆放
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        //间距
        rv_articlejinbao.addItemDecoration(new DividerItemDecoration(10));
        rv_articlejinbao.setLayoutManager(linearLayoutManager);
    }

    //获取文章头部数据成功
    @Override
    public void onChannalArticleInfoSucess(ChannalArticleInfoBean infoBeanList1) {
        infoBeanList = infoBeanList1;
        tvChannalarticleauthor.setText(infoBeanList.getAuthor().getUsername());
        tvChannalarticlecommentnum.setText(readnum);
        tvChannalarticletitle.setText(infoBeanList.getTitle());
        tvChannalarticleiconname.setText(infoBeanList.getCat().getName());
        tvChannalarticletime.setText(infoBeanList.getPublish_time());
        Glide.with(this).load(infoBeanList.getImg()).into(ivChannalarticlebg);
    }

    //获取文章头部数据失败
    @Override
    public void onChannalArticleInfoFaild(String msg) {
        Toast.makeText(ChannalArticleActivity.this, msg, Toast.LENGTH_LONG).show();
    }

    //获取文章推荐数据功能
    @Override
    public void onChannalArticleFooterSucess(ChannalArticleFooterBean footerBean) {
        List<ChannalArticleRecommendBean> list = new ArrayList<>();
        list = footerBean.getRecommend();
        List<ChannalArticleTagsBean> taglist = new ArrayList<>();
        taglist = footerBean.getTags();
        ChannalArticleJinBaoAdapter adapter = new ChannalArticleJinBaoAdapter(this, list);
        rv_articlejinbao.setAdapter(adapter);
        final List<ChannalArticleRecommendBean> finalList = list;
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Intent intent = new Intent(ChannalArticleActivity.this, ChannalArticleActivity.class);
                intent.putExtra("id", finalList.get(position).getId() + "");
                startActivity(intent);
            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        });
        ChannalArticleTuiJianAdapter adapter1 = new ChannalArticleTuiJianAdapter(this, taglist);
        rv_articleTuiJian.setAdapter(adapter1);
        final List<ChannalArticleTagsBean> finalTaglist = taglist;
        adapter1.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                if (finalTaglist.get(position).getType() == 3) {
                    Intent intent = new Intent(ChannalArticleActivity.this, CategoryActivity.class);
                    intent.putExtra("id", finalTaglist.get(position).getId() + "");
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(ChannalArticleActivity.this, StarItemActivity.class);
                    intent.putExtra("sid", finalTaglist.get(position).getId() + "");
                    startActivity(intent);
                }
            }

            @Override
            public void onItemLongClick(View view, int position) {
            }
        });
    }

    //获取文章推荐数据失败
    @Override
    public void onChannalArticleFooteFaild(String msg) {
        Toast.makeText(ChannalArticleActivity.this, msg, Toast.LENGTH_LONG).show();
    }

    //获取文章内容数据功能
    @Override
    public void onChannalArticleContentSucess(List<String> contentlist, List<ChannalArticleIMGBean> imgBeanList) {
        List<String> contentlist1 = new ArrayList<>();
        List<String> alllist = new ArrayList<>();
        String content = null;
        for (int i = 0; i < contentlist.size(); i++) {
            content = contentlist.get(i);
            content = content.substring(content.indexOf(">") + 1, content.lastIndexOf("<"));
            contentlist1.add(content);
        }
        int j = 0;
        for (int i = 0; i < contentlist1.size(); i++) {
            if (contentlist1.get(i).contains("<!--") == true) {
                if (j < imgBeanList.size()) {
                    alllist.add(imgBeanList.get(j).getSrc());
                    j++;
                } else {
                    continue;
                }
            } else {
                CharSequence result= Html.fromHtml(contentlist1.get(i),null,null);
                alllist.add(result.toString());
            }
        }
        ChannalArticleContentAdapter articleContentAdapter = new ChannalArticleContentAdapter(this,
                alllist);
        rv_articleContent.setAdapter(articleContentAdapter);
    }

    //获取文章内容失败
    @Override
    public void onChannalArticleContentFaild(String msg) {
        Toast.makeText(ChannalArticleActivity.this, msg, Toast.LENGTH_LONG).show();
    }

    //获取投票数据成功
    @Override
    public void onChannalArticleAttitudeSucess(List<ChannalArticleAttitudeBean> attitudeBeanList1) {
        attitudeBeanList = attitudeBeanList1;
    }

    //获取投票数据失败
    @Override
    public void onChannalArticleAttitudeFaild(String msg) {
        Toast.makeText(ChannalArticleActivity.this, msg, Toast.LENGTH_LONG).show();
    }

    //获取投票数据功能
    @Override
    public void onChannalArticleCommentAttitudeSucess(ArticleCommentAttitudeBean attitudeBean,
                                                      ArticleBean articleBean) {
        for (int i = 0; i < attitudeBeanList.size(); i++) {
            ChannalArticleVoteBean voteBean = new ChannalArticleVoteBean();
            voteBean.setVoteid(id);
            voteBean.setImage(attitudeBeanList.get(i).getPic());
            voteBean.setName(attitudeBeanList.get(i).getName());
            voteBean.setVotenum(attitudeBean.getList().get(i).getNumber());
            voteBeanList.add(voteBean);
        }
        App.getLiteOrm().insert(voteBeanList);
        tv_votenum.setText(attitudeBean.getCount() + "");
        tvChannalarticlecommentnum.setText(articleBean.getReplynum() + "");
        voteNum = attitudeBean.getCount();
        initVoteData();
    }

    private void initVoteData() {
        ChannalArticleVoteAdapter adapter = new ChannalArticleVoteAdapter(this, voteBeanList, voteNum);
        rv_articleAttitude.setAdapter(adapter);
    }

    //获取投票数据失败
    @Override
    public void onChannalArticleCommentAttitudeFaild(String msg) {
        Toast.makeText(ChannalArticleActivity.this, msg, Toast.LENGTH_LONG).show();
    }

    //获取评论数据成功
    @Override
    public void onChannalArticleCommentSucess(ArticleCommentBean commentBean) {
        List<ArticleCommentFirstListBean> commentListBeen = commentBean.getList();
        tv_articleCommmentmore.setText("查看更多风骚评论（" + commentBean.getCount() + "条）");
        ChannalArticleCommentAdapter adapter = new ChannalArticleCommentAdapter(this, commentListBeen);
        rv_channalarticlecomment.setAdapter(adapter);


    }

    //获取评论数据失败
    @Override
    public void onChannalArticleCommentFaild(String msg) {
        Toast.makeText(ChannalArticleActivity.this, msg, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onArticleCommentAllSucess(List<ArticleCommentAllListBean> infoBeanList) {
        //添加弹幕
        for (int i = 0; i < infoBeanList.size(); i++) {
            mIDanmakuItem = new DanmakuItem(this, infoBeanList.get(i).getContent(), mDanmakuView.getWidth());
            float f=(float)(Math.random()*(2)+1);
            mIDanmakuItem.setSpeedFactor(f);
            mIDanmakuItem.setTextSize(14);
            list.add(mIDanmakuItem);
        }
        mDanmakuView.addItem(list, true);
        //发送一条弹幕
        button = (Button) findViewById(R.id.danmu_send);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String comment = etChannalarticledanmu.getText().toString();
                Log.i("qwe", comment);
                InputMethodManager imm = (InputMethodManager) getSystemService(ChannalArticleActivity.INPUT_METHOD_SERVICE);
                // 隐藏软键盘
                imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);

                if (TextUtils.isEmpty(comment)) {
                    Toast.makeText(ChannalArticleActivity.this, "输入框为空", Toast.LENGTH_SHORT).show();
                } else {
                    IDanmakuItem item = new DanmakuItem(ChannalArticleActivity.this, new SpannableString(comment), mDanmakuView.getWidth(),0,R.color.red,20,1);
                    mDanmakuView.addItemToHead(item);
                }
                etChannalarticledanmu.setText("");
            }
        });
        if (rv_channalarticlecomment.isFocusable()) {
            mDanmakuView.setVisibility(View.VISIBLE);
            mDanmakuView.show();
        } else {
            mDanmakuView.hide();
        }
        ivChannalarticlebullt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!flag) {
                    flag = true;
                    mDanmakuView.setVisibility(View.GONE);
                    mDanmakuView.show();
                    ivChannalarticlebullt.setImageResource(R.mipmap.btn_bullet_off_light);
                } else {
                    flag = false;
                    mDanmakuView.setVisibility(View.VISIBLE);
                    ivChannalarticlebullt.setImageResource(R.mipmap.btn_bullet_on_light);

                }
            }
        });
    }

    @Override
    public void onArticleCommentAllFaild(String msg) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rl_share_copy:
                //1.获取当前分享的平台的实例
                Platform platform = ShareSDK.getPlatform(QZone.NAME);
                //2.添加相应的监听事件
                platform.setPlatformActionListener(new PlatformActionListener() {
                    //表示分享执行回调的函数
                    @Override
                    public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
                        if (action == Platform.ACTION_AUTHORIZING) {
                            Log.i("tag", "授权成功");
                            //构建分享的对象
                            QZone.ShareParams params = new QZone.ShareParams();
                            params.setText(infoBeanList.getTitle());
                            params.setImageUrl(infoBeanList.getImg());
                            //启动分享
                            platform.share(params);
                        } else if (action == Platform.ACTION_SHARE) {//分享成功
                            Log.i("tag", "分享成功");
                        }
                    }

                    //表示分享出错时回调
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("tag", "分享出错");
                        throwable.printStackTrace();
                    }

                    //取消分享时回调的
                    @Override
                    public void onCancel(Platform platform, int i) {
                        Log.i("tag", "取消分享");
                    }
                });
                //3.授权
                platform.authorize();
                break;
            case R.id.rl_share_qq:
                //1.获取当前分享的平台的实例
                 platform = ShareSDK.getPlatform(QQ.NAME);
                //2.添加相应的监听事件
                platform.setPlatformActionListener(new PlatformActionListener() {
                    //表示分享执行回调的函数
                    @Override
                    public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
                        if (action == Platform.ACTION_AUTHORIZING) {
                            Log.i("tag", "授权成功");
                            //构建分享的对象
                            QQ.ShareParams params = new QQ.ShareParams();
                            params.setText(infoBeanList.getTitle());
                            params.setImageUrl(infoBeanList.getImg());
                            //启动分享
                            platform.share(params);
                        } else if (action == Platform.ACTION_SHARE) {//分享成功
                            Log.i("tag", "分享成功");
                        }
                    }

                    //表示分享出错时回调
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("tag", "分享出错");
                        throwable.printStackTrace();
                    }

                    //取消分享时回调的
                    @Override
                    public void onCancel(Platform platform, int i) {
                        Log.i("tag", "取消分享");
                    }
                });
                //3.授权
                platform.authorize();
                break;
            case R.id.rl_share_qzone:
                //1.获取当前分享的平台的实例
                 platform = ShareSDK.getPlatform(QZone.NAME);
                //2.添加相应的监听事件
                platform.setPlatformActionListener(new PlatformActionListener() {
                    //表示分享执行回调的函数
                    @Override
                    public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
                        if (action == Platform.ACTION_AUTHORIZING) {
                            Log.i("tag", "授权成功");
                            //构建分享的对象
                            QZone.ShareParams params = new QZone.ShareParams();
                            params.setText(infoBeanList.getTitle());
                            params.setImageUrl(infoBeanList.getImg());
                            //启动分享
                            platform.share(params);
                        } else if (action == Platform.ACTION_SHARE) {//分享成功
                            Log.i("tag", "分享成功");
                        }
                    }

                    //表示分享出错时回调
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("tag", "分享出错");
                        throwable.printStackTrace();
                    }

                    //取消分享时回调的
                    @Override
                    public void onCancel(Platform platform, int i) {
                        Log.i("tag", "取消分享");
                    }
                });
                //3.授权
                platform.authorize();
                break;
            case R.id.rl_share_weibo:
                //1.获取当前分享的平台的实例
                platform = ShareSDK.getPlatform(SinaWeibo.NAME);
                //2.添加相应的监听事件
                platform.setPlatformActionListener(new PlatformActionListener() {
                    //表示分享执行回调的函数
                    @Override
                    public void onComplete(Platform platform, int action, HashMap<String, Object> hashMap) {
                        if (action == Platform.ACTION_AUTHORIZING) {
                            Log.i("tag", "授权成功");
                            //构建分享的对象
                            SinaWeibo.ShareParams params = new SinaWeibo.ShareParams();
                            params.setText(infoBeanList.getTitle());
                            params.setImageUrl(infoBeanList.getImg());
                            //启动分享
                            platform.share(params);
                        } else if (action == Platform.ACTION_SHARE) {//分享成功
                            Log.i("tag", "分享成功");
                        }
                    }

                    //表示分享出错时回调
                    @Override
                    public void onError(Platform platform, int i, Throwable throwable) {
                        Log.i("tag", "分享出错");
                        throwable.printStackTrace();
                    }

                    //取消分享时回调的
                    @Override
                    public void onCancel(Platform platform, int i) {
                        Log.i("tag", "取消分享");
                    }
                });
                //3.授权
                platform.authorize();
                break;
        }
    }

    static class ViewHolder {
        @InjectView(R.id.rl_share_qq)
        LinearLayout rlShareQq;
        @InjectView(R.id.rl_share_qzone)
        LinearLayout rlShareQzone;
        @InjectView(R.id.rl_share_copy)
        LinearLayout rlShareCopy;
        @InjectView(R.id.rl_share_weibo)
        LinearLayout rlShareWeibo;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
